package com.atguigu.job;

import com.atguigu.constant.RedisConstant;
import com.atguigu.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    //清理垃圾图片任务
    public void clearImg(){
    Set<String> imgNames=jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,
                                    RedisConstant.SETMEAL_PIC_DB_RESOURCES);

        for (String imgName : imgNames) {
            System.out.println("imgName"+imgName);
            //删除七牛云的垃圾图片
            QiniuUtils.deleteFileFromQiniu(imgName);
            //删除缓存当中的垃圾图片
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,imgName);
        }

    }


}
